<?php
require_once 'application/library/controller/gcLBasicAction.php';
require_once 'application/library/exception/gcExceptionDealer.php';
require_once 'application/modules/stock/constant/stock_constant_constant.php';
require_once 'application/modules/stock/constant/stock_constant_templatName.php';
require_once 'application/modules/stock/services/stock_services_stockAlertListService.php';

/**
 * 库存警报一览Controller
 * @author    Soochow University
 * @version   1.0
 * @exclude   作  成  日：2011/04/07
 */
class stock_stockAlertListController extends gcLBasicAction {
    /**
     * objService
     */
    private $objService;
    /**
     * 初期表示
     */
    public function indexAction() {
        try {
            $this->initMenu("1");
            $this->boolUserTypeCheck("1");
            $this->pvSetLabel();

            if ($this->getParam("ReturnFg")) {
                if ($this->getParam("ReturnFg") == "2") {
                    $arrMessage[0] = $this->getMessage("INFO-00001");
                }
                $this->setErrorMsg($arrMessage);
            }
            if (empty($arrCondition)) {
                $arrCondition = array();
                $arrCondition["curPage"] = 1;
                $arrCondition["pageSize"] = 10;
            }
            
            if ($this->getParam("PageModel")) {
                $strPageModel = $this->getParam("PageModel");
            } else {
                $strPageModel = 1;
            }
            $this->gcView->strPageModel = $strPageModel;
            sessionHelper::setPageData(stock_constant_constant::STOCK_ALERT_LIST, $arrCondition);

            $this->objService = new stock_services_stockAlertListService();

            $intCount = $this->objService->pbGetSearchCount($arrCondition);
            $objPager=$this->pagerInit($intCount, $arrCondition["curPage"], $arrCondition["pageSize"], pageSizeGroup::PAGE_SIZE_TEN, display::SHOW);
            $arrCondition["offset"] = $objPager->getOffset();
            $arrCondition["limit"] = $objPager->getLimit();
            if ($intCount>0) {
                $arrGoods = $this->objService->pbSearchGoods($arrCondition);
            }

            $this->gcView->intGoodsNum = $intCount;
            $this->gcView->arrGoods = $arrGoods;

            $this->gcView->render(stock_constant_templatName::STOCK_ALERT_LIST);
        } catch(Exception $e) {
            gcExceptionDealer::setException($e);
        }
    }

    /**
     * 初期化页面情报
     * pvSetLabel
     * @param null
     * @return null
     */
    private function pvSetLabel() {
        $this->gcView->title                          = $this->getLabel("stock_EC0001_PageTitle");
        $this->gcView->stock_EC0001_GoodsCode         = $this->getLabel("stock_EC0001_GoodsCode");
        $this->gcView->stock_EC0001_GoodsName         = $this->getLabel("stock_EC0001_GoodsName");
        $this->gcView->stock_EC0001_SalesPrice        = $this->getLabel("stock_EC0001_SalesPrice");
        $this->gcView->stock_EC0001_Yen               = $this->getLabel("stock_EC0001_Yen");
        $this->gcView->stock_EC0001_addGoods          = $this->getLabel("stock_EC0001_addGoods");
        $this->gcView->stock_EC0001_Link              = $this->getLabel("stock_EC0001_Link");
        $this->gcView->stock_EC0001_Class             = $this->getLabel("stock_EC0001_Class");
        $this->gcView->stock_EC0001_InNum             = $this->getLabel("stock_EC0001_InNum");
        $this->gcView->stock_EC0001_GetAll            = $this->getLabel("stock_EC0001_GetAll");
        $this->gcView->stock_EC0001_GetLeft           = $this->getLabel("stock_EC0001_GetLeft");
        $this->gcView->stock_EC0001_GetExcut          = $this->getLabel("stock_EC0001_GetExcut");
        $this->gcView->stock_EC0001_GetSet            = $this->getLabel("stock_EC0001_GetSet");
        $this->gcView->stock_EC0001_SearCondition     = $this->getLabel("stock_EC0001_SearCondition");
        $this->gcView->stock_EC0001_Clear             = $this->getLabel("stock_EC0001_Clear");
        $this->gcView->stock_EC0001_No                = $this->getLabel("stock_EC0001_No");
        $this->gcView->stock_EC0001_Check             = $this->getLabel("stock_EC0001_Check");
        $this->gcView->stock_EC0001_SalePrice         = $this->getLabel("stock_EC0001_SalePrice");
        $this->gcView->stock_EC0001_H1                = $this->getLabel("stock_EC0001_H1");
        $this->gcView->stock_EC0001_H2                = $this->getLabel("stock_EC0001_H2");
        $this->gcView->stock_EC0001_Title2            = $this->getLabel("stock_EC0001_Title2");
        $this->gcView->stock_EC0001_Label             = $this->getLabel("stock_EC0001_Label");
        $this->gcView->stock_EC0001_Num               = $this->getLabel("stock_EC0001_Num");
        $this->gcView->stock_EC0001_Variation         = $this->getLabel("stock_EC0001_Variation");
        $this->gcView->stock_EC0001_SupplierNum       = $this->getLabel("stock_EC0001_SupplierNum");
        $this->gcView->stock_EC0001_SupplierName      = $this->getLabel("stock_EC0001_SupplierName");
        $this->gcView->stock_EC0001_alert             = $this->getLabel("stock_EC0001_alert");
        $this->gcView->stock_EC0001_ConditionEdit     = $this->getLabel("stock_EC0001_ConditionEdit");
        $this->gcView->stock_EC0001_Suggest           = $this->getLabel("stock_EC0001_Suggest");
        $this->gcView->stock_EC0001_Max               = $this->getLabel("stock_EC0001_Max");
        $this->gcView->stock_EC0001_Min               = $this->getLabel("stock_EC0001_Min");
        $this->gcView->stock_EC0001_MakeOrder         = $this->getLabel("stock_EC0001_MakeOrder");
        $this->gcView->stock_EC0001_Save              = $this->getLabel("stock_EC0001_Save");
        $this->gcView->stock_EC0001_NoSuggest           = $this->getLabel("stock_EC0001_NoSuggest");
        $this->gcView->stock_EC0001_StockLimit          = $this->getLabel("stock_EC0001_StockLimit");
        $this->gcView->stock_EC0001_Sales               = $this->getLabel("stock_EC0001_Sales");
        $this->gcView->stock_EC0001_Notice1               = $this->getLabel("stock_EC0001_Notice1");
        $this->gcView->stock_EC0001_Notice2               = $this->getLabel("stock_EC0001_Notice2");
    }

    /**
     * 检索
     */
    public function searchAction() {
        try {
            if ($this->getRequest()->isXmlHttpRequest()) {
                if ($this->getParam("Flag") == "1") {
                    $arrCondition = array("GoodsCode"  => $this->getParam("GoodsCode"),
                                      "GoodsName"  => $this->getParam("GoodsName"),
                                      "StockNumFg"    => $this->getParam("StockNumFg"),
                                      "StockNumFrom"    => $this->getParam("StockNumFrom"),
                                      "StockNumTo"    => $this->getParam("StockNumTo"));
                    sessionHelper::setPageData(stock_constant_constant::STOCK_ALERT_LIST, $arrCondition);
                } else {
                    $arrCondition = sessionHelper::getPageData(stock_constant_constant::STOCK_ALERT_LIST);
                    $arrCondition["pageSize"] = $this->getParam("pageSize");
                    $arrCondition["orderColumn"] = $this->getParam("orderColumn");
                    $arrCondition["order"] = $this->getParam("order");
                }
                $this->objService   = new stock_services_stockAlertListService();
                $intCount = $this->objService->pbGetSearchCount($arrCondition);
                $objPager = $this->getPagerParam($intCount);
                if ($intCount != 0) {
                    $arrCondition["offset"]      = $objPager->getOffset();
                    $arrCondition["limit"]        = $objPager->getLimit();
                    $CurPage                         = $objPager->getCurPage();

                    $arrData = $this->objService->pbSearchGoods($arrCondition);
                    $arrResault = array(
                        "count"      => $intCount,
                        "curPage"      => $CurPage,
                        "searchData" => $arrData
                    );
                } else {
                    $arrResault = array(
                        "count"      => 0,
                        "curPage"    => $objPager->getCurPage(),
                        "searchData" => "");
                }
                jsonHelper::outPutJson($arrResault);
            } else {
                gcExceptionDealer::throwGcException();
            }
        } catch(Exception $e) {
            gcExceptionDealer::setException($e);
        }
    }

    /**
     * 保存库存警报设置
     */
    public function saveAction() {
        try {
            if ($this->getRequest()->isXmlHttpRequest()) {
                $arrCondition = array(
                    "Id"        => $this->getParam("Id",true),
                    "Ver"       => $this->getParam("Ver",true),
                    "Suggest"   => $this->getParam("Suggest",true),
                    "Min"       => $this->getParam("Min",true),
                    "Max"       => $this->getParam("Max",true));

                $this->objService   = new stock_services_stockAlertListService();
                $intCount = $this->objService->pbGoodsStockAlertUpdate($arrCondition);
                $arrResault = array(
                    "count"      => $intCount
                );
                if ($arrResault["count"] == 0) {
                    
                    $arrResault["ReturnFg"] = $this->getMessage("ERR-00002");
                }
                jsonHelper::outPutJson($arrResault);
            } else {
                gcExceptionDealer::throwGcException();
            }
        } catch(Exception $e) {
            gcExceptionDealer::setException($e);
        }
    }

    /**
     * 订单
     */
    public function orderAction() {
        try {
            if ($this->getRequest()->isXmlHttpRequest()) {
                $arrCondition = $this->getParam("Goods", true);
                sessionHelper::setPageData(stock_constant_constant::ORDER_EDIT, $arrCondition);
                $arrResault = array(
                    "count"      => 1
                );
                jsonHelper::outPutJson($arrResault);
            } else {
                gcExceptionDealer::throwGcException();
            }
        } catch(Exception $e) {
            gcExceptionDealer::setException($e);
        }
    }
}